/**
 * 活动详情对话框（可用于添加和修改对话框）
 */
var ActivityInfoDlg = {
    data: {
        activityId: "",
        activityName: "",
        activityNote: "",
        activityDiscount: "",
        startTime: "",
        endTime: "",
        isTimeout: ""
    }
};

ActivityInfoDlg.validateForm = function () {

    var data = ActivityInfoDlg.data;

    if (!data.activityName) {
        return "请输入活动名称";
    }
    if (!data.activityNote) {
        return "请输入活动简介";
    }
    if (!data.activityDiscount) {
        return "请输入折扣力度";
    }
    if (!data.startTime) {
        return "请输入开始时间";
    }
    if (!data.endTime) {
        return "请输入结束时间";
    }
    return true;
};

/**
 * 关闭此对话框
 */
ActivityInfoDlg.close = function () {
    parent.layer.close(window.parent.activity.layerIndex);
};
/**
 * 提交修改
 */
ActivityInfoDlg.editSubmit = function () {
    var ajax = new $ax(Feng.ctxPath + "/activity/edit", function (data) {
        window.parent.Feng.success("修改成功!");
        if (window.parent.activity !== undefined) {
            window.parent.activity.table.refresh();
            ActivityInfoDlg.close();
        }
    }, function (data) {
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(ActivityInfoDlg.data);
    ajax.start();
};

$(function () {
    //获取车辆信息
    var ajax = new $ax(Feng.ctxPath + "/activity/getActivityInfo?activityId=" + Feng.getUrlParam("activityId"));
    var result = ajax.start();
    ActivityInfoDlg.data = result.data;
    ActivityInfoDlg.app = new Vue({
        el: '#activityForm',
        data: ActivityInfoDlg.data,
        methods: {
            submitForm: function (e) {
                e.preventDefault();
            },
            ensure: function () {
                ActivityInfoDlg.data.startTime = Feng.getStartTime();
                ActivityInfoDlg.data.endTime = Feng.getEndTime();
                var result = ActivityInfoDlg.validateForm();
                if (result === true) {
                    ActivityInfoDlg.editSubmit();
                } else {
                    Feng.alert(result);
                }
            },
            close: function () {
                ActivityInfoDlg.close();
            }
        }
    });
    //放入时间内容
    Feng.initStartTime(ActivityInfoDlg.data.startTime);
    Feng.initEndTime(ActivityInfoDlg.data.endTime);
});
